//
//  ViewController.swift
//  表情键盘
//
//  Created by whtapple on 4/2/16.
//  Copyright © 2016 whtapple. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet var textView: UITextView!
    override func viewDidLoad() {
        super.viewDidLoad()
        //将键盘变成自己的
        textView.inputView = keyboardView
        keyboardView.textView = textView

        //成为第一响应者
        textView.becomeFirstResponder()
//        emojiDamo()
//       let package = HTEmotionModelManager.sharedManager.loadPackages()
//        Xprint(msg: "package\(package)")
    }
//    private func emojiDamo(){
//        let code = "0x1f604"
//        let scanner = NSScanner(string: code)
//        var result: UInt32 = 0
//        scanner.scanHexInt(&result)
//        let salar = UnicodeScalar(result)
//        let emoji = String(Character(salar))
//        print("emoji\(emoji)")
//    
//    }
    
    @IBAction func clickButton(sender: UIButton) {
        var result = ""
        textView.attributedText.enumerateAttributesInRange(NSRange(location: 0, length: textView.attributedText.length), options: NSAttributedStringEnumerationOptions(rawValue: 0)) { (dict, Range, _) -> Void in
            if let attachment = dict["NSAttachment"] as? HTEmotionAttachment{
            let name = attachment.chs
                result += name!
            }else{
                let substring = (self.textView.attributedText.string as NSString).substringWithRange(Range)
                result += substring
            }
        }
        print("\(result)")
    }
    //懒加载数据
    private lazy var keyboardView: HTkeyboardEmotionView = HTkeyboardEmotionView()


}

